package cn.serein.charging.device.controller;

import cn.serein.charging.common.pojo.JsonResult;
import cn.serein.charging.common.pojo.param.GunStatusUpdateParam;
import cn.serein.charging.common.pojo.vo.StationInfoVO;
import cn.serein.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("device")
@Api(tags = "设备接口")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @GetMapping("/station/near")
    @ApiOperation(value = "获取附近场站信息")
    public JsonResult getNearStation(Double longitude, Double latitude, Double distance){
        log.debug("获取附近场站信息:{},{},{}",longitude,latitude,distance);
        List<StationInfoVO> stationInfoVOList = deviceService.getNearStation(longitude, latitude, distance);

        return JsonResult.success(200, "获取附近场站信息成功", stationInfoVOList);
    }



    @ApiOperation(value = "获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult getStationInfo(@PathVariable("gunId") Integer gunId) {
        // 打印日志
        log.debug("获取场站信息:{}" , gunId);
        StationInfoVO stationInfoVO = deviceService.getStationInfo(gunId);

        JsonResult ok = JsonResult.success(200, "获取成功", stationInfoVO);
        log.debug("获取场站信息:{}" , ok);
        return ok;

    }

    @ApiOperation("更新枪状态")
    @PostMapping("/station/gun/status/update")
    public JsonResult updateGunStatus(@RequestBody GunStatusUpdateParam param) {
        log.debug("更新枪状态:{}",param);
        Boolean success = deviceService.updateGunStatus(param);
        JsonResult ok = JsonResult.success(200, "获取成功", success);
        log.debug("更新枪状态:{},出参:{}",param,ok);
        return ok;
    }


}
